Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to match belong_to with touch #222

Closed
wants to merge 2 commits into from

Conversation

panupan
Copy link
Contributor

@panupan panupan commented Jan 17, 2013

This option has been missing but is pretty much the same thing as matching the validate option. It could probably be refactored to prevent code duplication.

@drapergeek
Copy link
Contributor

@panupan Thanks for the pull!

I like this idea. The only thing that I do not like is the fact that if I have a model where I have specified touch and I am not currently specifying that in my tests, this will cause my matcher to fail. If I haven't specified it, I don't think it should be tested.

I do see that it is handled this way in the validate option and I don't agree with that.

Can you remove that please and we'll review from that point.

@mxie
Copy link
Contributor

mxie commented Apr 4, 2013

Just wanted to check in and see if you had any updates on this. Please also rebase once you do since there have been many changes to master since this was last reviewed. Thanks!

Also fixes validate failing when specified on model but not on matcher.
@panupan
Copy link
Contributor Author

panupan commented Apr 10, 2013

@drapergeek Hello, I fixed touch and validate to work how you suggested, I also added some tests to verify it.

@mxie It should be up-to-date and good to go now.

@@ -258,10 +266,19 @@ def join_table_exists?
end

def validate_correct?
if !@validate && !reflection.options[:validate] || @validate == reflection.options[:validate]
if !@options.key?(:validate) || @options[:validate] == (reflection.options[:validate] == true ? true : false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !@options.key?(:validate) change is good, but instead of:

@options[:validate] == (reflection.options[:validate] == true ? true : false)

I think you can just do:

@options[:validate] == reflection.options[:validate]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, that was breaking some tests. Because Rails defaults :validate to false so reflection.options[:validate] could be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is:

@options[:validate] == !!reflection.options[:validate]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@options[:validate] == !!reflection.options[:validate] is better, but perhaps we should add back in the check for reflection.options[:validate]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mixie I'm not quite sure what adding that back in will work. It was causing the behavior drapergeek was describing above, where it would cause the matcher would fail if validate was specified in the model but not the matcher. BTW, I amended my last commit to use !!.

@panupan
Copy link
Contributor Author

panupan commented Apr 25, 2013

Hello, can someone review this again? It should be good to go.

@drapergeek
Copy link
Contributor

Thanks for this @panupan.

🚀

Also I really appreciate you fixing up the validate option as well. Good job!

@drapergeek drapergeek closed this Apr 26, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants